package com.sandking.db.bean;

import com.sandking.tools.SK_Map;
import java.util.ArrayList;
import com.sandking.db.cache.YhCache;
import com.alibaba.fastjson.JSON;
import java.util.Map;
import com.sandking.io.SK_OutputStream;
import java.util.List;
import com.sandking.io.SK_InputStream;
import com.sandking.db.cache.YhljxxCache;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.io.ByteArrayOutputStream;

/**
 * 用户累计信息
 */
public class Yhljxx {

	public static final String TABLENAME = "用户累计信息";
	public static final String CLASSNAME = "Yhljxx"; 
	/**
	 * 需要更新字段集
	 */
	private Map<String, Object> updateColumns;

	/** id */
	private int id;
	
	/** 用户_id */
	private int yh_id;
	
	/** 充值金额 */
	private long czje;
	
	/** 掠夺金币 */
	private long ldjb;
	
	/** 掠夺水 */
	private long lds;
	
	/** 清除障碍数 */
	private long qczas;
	
	/** 技能升级次数 */
	private long jnsjcs;
	
	/** 战胜玩家次数 */
	private long zswjcs;
	
	/** 充值元宝数 */
	private long czybs;
	
	/** 登录天数 */
	private long dlts;
	
	
	public Yhljxx() {
		super();
	}
	
	public Yhljxx(int id, int yh_id, long czje, long ldjb, long lds, long qczas, long jnsjcs, long zswjcs, long czybs, long dlts) {
		super();
		this.id = id;
		this.yh_id = yh_id;
		this.czje = czje;
		this.ldjb = ldjb;
		this.lds = lds;
		this.qczas = qczas;
		this.jnsjcs = jnsjcs;
		this.zswjcs = zswjcs;
		this.czybs = czybs;
		this.dlts = dlts;
	}
	
	public Map<String, Object> getUpdateColumns() {
		if(updateColumns == null)
			updateColumns = new HashMap<String, Object>();
		return updateColumns;
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
		addUpdateColumn("id",id);
	}
	
	public void changeIdWith(int id){
		this.id += id;
		setId(this.id);
	}
	
	public void changeIdWithMin(int id,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMax(int id,int max){
		this.id += id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMaxMin(int id,int max,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}	
	public int getYh_id() {
		return yh_id;
	}
	
	public void setYh_id(int yh_id) {
		this.yh_id = yh_id;
		addUpdateColumn("用户_id",yh_id);
	}
	
	public void changeYh_idWith(int yh_id){
		this.yh_id += yh_id;
		setYh_id(this.yh_id);
	}
	
	public void changeYh_idWithMin(int yh_id,int min){
		this.yh_id += yh_id;
		this.yh_id = this.yh_id < min ? min : this.yh_id;
		setYh_id(this.yh_id);
	}
	
	public void changeYh_idWithMax(int yh_id,int max){
		this.yh_id += yh_id;
		this.yh_id = this.yh_id > max ? max : this.yh_id;
		setYh_id(this.yh_id);
	}
	
	public void changeYh_idWithMaxMin(int yh_id,int max,int min){
		this.yh_id += yh_id;
		this.yh_id = this.yh_id < min ? min : this.yh_id;
		this.yh_id = this.yh_id > max ? max : this.yh_id;
		setYh_id(this.yh_id);
	}	
	public long getCzje() {
		return czje;
	}
	
	public void setCzje(long czje) {
		this.czje = czje;
		addUpdateColumn("充值金额",czje);
	}
	
	public void changeCzjeWith(long czje){
		this.czje += czje;
		setCzje(this.czje);
	}
	
	public void changeCzjeWithMin(long czje,long min){
		this.czje += czje;
		this.czje = this.czje < min ? min : this.czje;
		setCzje(this.czje);
	}
	
	public void changeCzjeWithMax(long czje,long max){
		this.czje += czje;
		this.czje = this.czje > max ? max : this.czje;
		setCzje(this.czje);
	}
	
	public void changeCzjeWithMaxMin(long czje,long max,long min){
		this.czje += czje;
		this.czje = this.czje < min ? min : this.czje;
		this.czje = this.czje > max ? max : this.czje;
		setCzje(this.czje);
	}	
	public long getLdjb() {
		return ldjb;
	}
	
	public void setLdjb(long ldjb) {
		this.ldjb = ldjb;
		addUpdateColumn("掠夺金币",ldjb);
	}
	
	public void changeLdjbWith(long ldjb){
		this.ldjb += ldjb;
		setLdjb(this.ldjb);
	}
	
	public void changeLdjbWithMin(long ldjb,long min){
		this.ldjb += ldjb;
		this.ldjb = this.ldjb < min ? min : this.ldjb;
		setLdjb(this.ldjb);
	}
	
	public void changeLdjbWithMax(long ldjb,long max){
		this.ldjb += ldjb;
		this.ldjb = this.ldjb > max ? max : this.ldjb;
		setLdjb(this.ldjb);
	}
	
	public void changeLdjbWithMaxMin(long ldjb,long max,long min){
		this.ldjb += ldjb;
		this.ldjb = this.ldjb < min ? min : this.ldjb;
		this.ldjb = this.ldjb > max ? max : this.ldjb;
		setLdjb(this.ldjb);
	}	
	public long getLds() {
		return lds;
	}
	
	public void setLds(long lds) {
		this.lds = lds;
		addUpdateColumn("掠夺水",lds);
	}
	
	public void changeLdsWith(long lds){
		this.lds += lds;
		setLds(this.lds);
	}
	
	public void changeLdsWithMin(long lds,long min){
		this.lds += lds;
		this.lds = this.lds < min ? min : this.lds;
		setLds(this.lds);
	}
	
	public void changeLdsWithMax(long lds,long max){
		this.lds += lds;
		this.lds = this.lds > max ? max : this.lds;
		setLds(this.lds);
	}
	
	public void changeLdsWithMaxMin(long lds,long max,long min){
		this.lds += lds;
		this.lds = this.lds < min ? min : this.lds;
		this.lds = this.lds > max ? max : this.lds;
		setLds(this.lds);
	}	
	public long getQczas() {
		return qczas;
	}
	
	public void setQczas(long qczas) {
		this.qczas = qczas;
		addUpdateColumn("清除障碍数",qczas);
	}
	
	public void changeQczasWith(long qczas){
		this.qczas += qczas;
		setQczas(this.qczas);
	}
	
	public void changeQczasWithMin(long qczas,long min){
		this.qczas += qczas;
		this.qczas = this.qczas < min ? min : this.qczas;
		setQczas(this.qczas);
	}
	
	public void changeQczasWithMax(long qczas,long max){
		this.qczas += qczas;
		this.qczas = this.qczas > max ? max : this.qczas;
		setQczas(this.qczas);
	}
	
	public void changeQczasWithMaxMin(long qczas,long max,long min){
		this.qczas += qczas;
		this.qczas = this.qczas < min ? min : this.qczas;
		this.qczas = this.qczas > max ? max : this.qczas;
		setQczas(this.qczas);
	}	
	public long getJnsjcs() {
		return jnsjcs;
	}
	
	public void setJnsjcs(long jnsjcs) {
		this.jnsjcs = jnsjcs;
		addUpdateColumn("技能升级次数",jnsjcs);
	}
	
	public void changeJnsjcsWith(long jnsjcs){
		this.jnsjcs += jnsjcs;
		setJnsjcs(this.jnsjcs);
	}
	
	public void changeJnsjcsWithMin(long jnsjcs,long min){
		this.jnsjcs += jnsjcs;
		this.jnsjcs = this.jnsjcs < min ? min : this.jnsjcs;
		setJnsjcs(this.jnsjcs);
	}
	
	public void changeJnsjcsWithMax(long jnsjcs,long max){
		this.jnsjcs += jnsjcs;
		this.jnsjcs = this.jnsjcs > max ? max : this.jnsjcs;
		setJnsjcs(this.jnsjcs);
	}
	
	public void changeJnsjcsWithMaxMin(long jnsjcs,long max,long min){
		this.jnsjcs += jnsjcs;
		this.jnsjcs = this.jnsjcs < min ? min : this.jnsjcs;
		this.jnsjcs = this.jnsjcs > max ? max : this.jnsjcs;
		setJnsjcs(this.jnsjcs);
	}	
	public long getZswjcs() {
		return zswjcs;
	}
	
	public void setZswjcs(long zswjcs) {
		this.zswjcs = zswjcs;
		addUpdateColumn("战胜玩家次数",zswjcs);
	}
	
	public void changeZswjcsWith(long zswjcs){
		this.zswjcs += zswjcs;
		setZswjcs(this.zswjcs);
	}
	
	public void changeZswjcsWithMin(long zswjcs,long min){
		this.zswjcs += zswjcs;
		this.zswjcs = this.zswjcs < min ? min : this.zswjcs;
		setZswjcs(this.zswjcs);
	}
	
	public void changeZswjcsWithMax(long zswjcs,long max){
		this.zswjcs += zswjcs;
		this.zswjcs = this.zswjcs > max ? max : this.zswjcs;
		setZswjcs(this.zswjcs);
	}
	
	public void changeZswjcsWithMaxMin(long zswjcs,long max,long min){
		this.zswjcs += zswjcs;
		this.zswjcs = this.zswjcs < min ? min : this.zswjcs;
		this.zswjcs = this.zswjcs > max ? max : this.zswjcs;
		setZswjcs(this.zswjcs);
	}	
	public long getCzybs() {
		return czybs;
	}
	
	public void setCzybs(long czybs) {
		this.czybs = czybs;
		addUpdateColumn("充值元宝数",czybs);
	}
	
	public void changeCzybsWith(long czybs){
		this.czybs += czybs;
		setCzybs(this.czybs);
	}
	
	public void changeCzybsWithMin(long czybs,long min){
		this.czybs += czybs;
		this.czybs = this.czybs < min ? min : this.czybs;
		setCzybs(this.czybs);
	}
	
	public void changeCzybsWithMax(long czybs,long max){
		this.czybs += czybs;
		this.czybs = this.czybs > max ? max : this.czybs;
		setCzybs(this.czybs);
	}
	
	public void changeCzybsWithMaxMin(long czybs,long max,long min){
		this.czybs += czybs;
		this.czybs = this.czybs < min ? min : this.czybs;
		this.czybs = this.czybs > max ? max : this.czybs;
		setCzybs(this.czybs);
	}	
	public long getDlts() {
		return dlts;
	}
	
	public void setDlts(long dlts) {
		this.dlts = dlts;
		addUpdateColumn("登录天数",dlts);
	}
	
	public void changeDltsWith(long dlts){
		this.dlts += dlts;
		setDlts(this.dlts);
	}
	
	public void changeDltsWithMin(long dlts,long min){
		this.dlts += dlts;
		this.dlts = this.dlts < min ? min : this.dlts;
		setDlts(this.dlts);
	}
	
	public void changeDltsWithMax(long dlts,long max){
		this.dlts += dlts;
		this.dlts = this.dlts > max ? max : this.dlts;
		setDlts(this.dlts);
	}
	
	public void changeDltsWithMaxMin(long dlts,long max,long min){
		this.dlts += dlts;
		this.dlts = this.dlts < min ? min : this.dlts;
		this.dlts = this.dlts > max ? max : this.dlts;
		setDlts(this.dlts);
	}	
	
	//用户_id
	public Yh getYhPkYh_id(){
		return YhCache.getById(yh_id);
	}
	public void addUpdateColumn(String key, Object val) {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.put(key, val);
	}
	
	public void clearUpdateColumn() {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.clear();
	}
	
	public Map<String, Object> toMap(){
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", this.id);
        result.put("yh_id", this.yh_id);
        result.put("czje", this.czje);
        result.put("ldjb", this.ldjb);
        result.put("lds", this.lds);
        result.put("qczas", this.qczas);
        result.put("jnsjcs", this.jnsjcs);
        result.put("zswjcs", this.zswjcs);
        result.put("czybs", this.czybs);
        result.put("dlts", this.dlts);
        return result;
    }
    
    public String toString(){
        return toMap().toString();
    }
    
    public String toJson(){
    	return JSON.toJSONString(toMap());
    }
    
    /**
     * 数据库源字段Map
     */
    public Map<String, Object> toColumnNameMap(){
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", this.id);
        result.put("用户_id", this.yh_id);
        result.put("充值金额", this.czje);
        result.put("掠夺金币", this.ldjb);
        result.put("掠夺水", this.lds);
        result.put("清除障碍数", this.qczas);
        result.put("技能升级次数", this.jnsjcs);
        result.put("战胜玩家次数", this.zswjcs);
        result.put("充值元宝数", this.czybs);
        result.put("登录天数", this.dlts);
        return result;
    }
    
    public String toColumnNameString(){
        return toColumnNameMap().toString();
    }
    
    public byte[] toBytes() throws Exception {
    	try (ByteArrayOutputStream out = new ByteArrayOutputStream();) {
		    SK_OutputStream.writeInt(out,this.id);
		    SK_OutputStream.writeInt(out,this.yh_id);
		    SK_OutputStream.writeLong(out,this.czje);
		    SK_OutputStream.writeLong(out,this.ldjb);
		    SK_OutputStream.writeLong(out,this.lds);
		    SK_OutputStream.writeLong(out,this.qczas);
		    SK_OutputStream.writeLong(out,this.jnsjcs);
		    SK_OutputStream.writeLong(out,this.zswjcs);
		    SK_OutputStream.writeLong(out,this.czybs);
		    SK_OutputStream.writeLong(out,this.dlts);
		    return out.toByteArray();
    	}catch (Exception e) {
            throw e;
        }
    }
    
     public static Yhljxx createForBytes(byte[] _byte) throws Exception {
     	try (ByteArrayInputStream in = new ByteArrayInputStream(_byte);) {
	     	Yhljxx yhljxx = new Yhljxx();
		    yhljxx.id = SK_InputStream.readInt(in,null);
		    yhljxx.yh_id = SK_InputStream.readInt(in,null);
		    yhljxx.czje = SK_InputStream.readLong(in,null);
		    yhljxx.ldjb = SK_InputStream.readLong(in,null);
		    yhljxx.lds = SK_InputStream.readLong(in,null);
		    yhljxx.qczas = SK_InputStream.readLong(in,null);
		    yhljxx.jnsjcs = SK_InputStream.readLong(in,null);
		    yhljxx.zswjcs = SK_InputStream.readLong(in,null);
		    yhljxx.czybs = SK_InputStream.readLong(in,null);
		    yhljxx.dlts = SK_InputStream.readLong(in,null);
		    return yhljxx;
    	}catch (Exception e) {
            throw e;
        }
     }
    
    /**
     * 根据list创建对象
     */
    public static List<Yhljxx> createForColumnNameList(List<Map<String, Object>> list){
    	List<Yhljxx> yhljxxs = new ArrayList<Yhljxx>();
		for (Map<String, Object> map : list) {
			yhljxxs.add(createForColumnNameMap(map));
		}
		return yhljxxs;
    }
    
    /**
     * 根据map创建对象
     */
    public static Yhljxx createForColumnNameMap(Map<String, Object> map){
    	Yhljxx obj = new Yhljxx();
	    obj.id = SK_Map.getInt("id", map);
	    obj.yh_id = SK_Map.getInt("用户_id", map);
	    obj.czje = SK_Map.getLong("充值金额", map);
	    obj.ldjb = SK_Map.getLong("掠夺金币", map);
	    obj.lds = SK_Map.getLong("掠夺水", map);
	    obj.qczas = SK_Map.getLong("清除障碍数", map);
	    obj.jnsjcs = SK_Map.getLong("技能升级次数", map);
	    obj.zswjcs = SK_Map.getLong("战胜玩家次数", map);
	    obj.czybs = SK_Map.getLong("充值元宝数", map);
	    obj.dlts = SK_Map.getLong("登录天数", map);
        return obj;
    }
    
    /**
     * 根据list创建对象
     */
    public static List<Yhljxx> createForList(List<Map<String, Object>> list){
    	List<Yhljxx> yhljxxs = new ArrayList<Yhljxx>();
		for (Map<String, Object> map : list) {
			yhljxxs.add(createForColumnNameMap(map));
		}
		return yhljxxs;
    }
    
    /**
     * 根据map创建对象
     */
    public static Yhljxx createForMap(Map<String, Object> map){
    	Yhljxx obj = new Yhljxx();
	    obj.id = SK_Map.getInt("id", map);
	    obj.yh_id = SK_Map.getInt("yh_id", map);
	    obj.czje = SK_Map.getLong("czje", map);
	    obj.ldjb = SK_Map.getLong("ldjb", map);
	    obj.lds = SK_Map.getLong("lds", map);
	    obj.qczas = SK_Map.getLong("qczas", map);
	    obj.jnsjcs = SK_Map.getLong("jnsjcs", map);
	    obj.zswjcs = SK_Map.getLong("zswjcs", map);
	    obj.czybs = SK_Map.getLong("czybs", map);
	    obj.dlts = SK_Map.getLong("dlts", map);
        return obj;
    }
    
    public static Yhljxx createForJson(String json){
    	Map<String, Object> map = JSON.parseObject(json);
    	return createForMap(map);
    }
    
    public static List<Yhljxx> createForJson(List<String> jsons){
    	List<Yhljxx> yhljxxs = new ArrayList<Yhljxx>();
    	for(String json : jsons){
    		yhljxxs.add(createForJson(json));
    	}
    	return yhljxxs;
    }
    
    /** 延迟插入数据库 */
    public Yhljxx insert(){
    	return YhljxxCache.insert(this);
    }
    /** 延迟更新数据库 */
    public Yhljxx update(){
    	return YhljxxCache.update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return YhljxxCache.delete(this);
    }
    /** 即时插入数据库 */
    public Yhljxx insertAndFlush(){
    	return YhljxxCache.insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Yhljxx updateAndFlush(){
    	return YhljxxCache.updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return YhljxxCache.deleteAndFlush(this);
    }
}